package controllers;

import java.util.List;

import flexjson.JSONSerializer;

import models.Post;
import play.mvc.Controller;

public class APIController extends Controller {
    
    public static void posts(int from, int count) {
        if (count == 0) {
            count = 12;
        }
        List<Post> posts = Post.find("order by postedAt desc").from(from).fetch(count);
        renderJSON(new JSONSerializer()
            .include("images")
            .include("images.width")
            .exclude("author.password")
            .serialize(posts));
    }
    
    public static void post(Long id) {
        Post post = Post.findById(id);
        renderJSON(new JSONSerializer()
            .include("images")
            .serialize(post));
    }
}
